package com.qumitech.visualnovel.component.amqp;


import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
 * @Author :  ZhChNing
 * @Descriptiom :
 * @Date Created in 2019/3/15 15:31
 */
@Configuration
public class RabbitConfig {
    /**
     * 新建队列（如果字符串的话 新建队列即可）
     *
     * @return
     */
    @Bean
    public Queue registerQueue() {
        return new Queue(AmqpConstant.weChat_Alarm);
    }

    /**
     * 定义交换器
     *
     * @return
     */
    @Bean
    public FanoutExchange registerExchange() {
        return new FanoutExchange(AmqpConstant.FANOUT_EXCHANGE_WE_CHAT_ALARM_EXCHANGE);
    }

    /**
     * 交换机与消息队列进行绑定 队列registerQueue 绑定 交换机 AmqpConstant.weChat_Alarm
     *
     * @param queueMessages
     * @param exchange
     * @return
     */
    @Bean
    Binding bindingExchangeMessages(@Qualifier("registerQueue") Queue queueMessages, FanoutExchange exchange) {
        return BindingBuilder.bind(queueMessages).to(exchange);
    }

}
